from collections import defaultdict

from common.mssql_helper import g_msql_inst
from common.utils import create_uuid

__author__ = "Ypf"
_date_ = "2019/8/1-14:13"


class Chycbj(object):
    @staticmethod
    def get_dic(sql):
        # 获取相应的对比sql查询语句
        res_list1 = g_msql_inst.fetch_all(sql)
        dic = defaultdict(dict)
        for (qdrq,ghdw,ywy,kf,bh,khhth,khbm,ggxh,pp,jhrq,sjhsdj,wchsl,kcsl) in res_list1:
            dic[create_uuid()] = [qdrq,ghdw,ywy,kf,bh,khhth,khbm,ggxh,pp,jhrq,sjhsdj,wchsl,kcsl]
        return dic

    @staticmethod
    def insert(db_insert_sql, dic, nowtime,ys):
        for key in dic:
            id = create_uuid()
            dic[key].append(nowtime + '-01')
            dic[key].append(id)
            dic[key].append(ys)
            value_tuple = tuple(dic[key])
            excuete_sql = db_insert_sql % value_tuple
            print(excuete_sql)
            g_msql_inst.db_excuete(excuete_sql)

            
"""
-- select  ghdw  from  k3_xsdd where ghdw not in (   select   ghdw  from k3_xsdd  where sjsj like '2019%') and sjsj
-- like '2018%';
-- select  ghdw from  k3_xsdd  where sjsj like '2019%' and ghdw='安图实验仪器（郑州）有限公司';

--select DISTINCT qdrq,ghdw,ywy,k3_khry.kf,bh,khhth,khbm,ggxh,pp,jhrq,sjhsdj,CONVERT ( FLOAT, sl ),CONVERT ( FLOAT, jbdwcksl ),CONVERT ( FLOAT, sl )-CONVERT ( FLOAT, jbdwcksl ) as wchsl from k3_xsdd,k3_khry  where  jhrq<(select convert(varchar(10),dateadd(month,-1,getdate()),23)) and gbbz!='Y' and k3_xsdd.ghdw=k3_khry.khmc
"""